//
//  UIViewController+TYSafeInsets.m
//  TYUIKit
//
//  Created by Pany on 2020/1/2.
//

#import "UIViewController+TYSafeInsets.h"

#import "UIScreen+TYFrame.h"

@implementation UIViewController (TYSafeInsets)

- (CGFloat)ty_safeTop {
    if (self.navigationController && self.navigationController.navigationBar.alpha > 0.001 && !self.navigationController.isNavigationBarHidden) {
        // 有导航栏，则返回导航栏底部坐标
        return self.navigationController.navigationBar.frame.origin.y + self.navigationController.navigationBar.frame.size.height;
    } else if (self.presentingViewController &&
        self.presentingViewController.presentedViewController.modalPresentationStyle == UIModalPresentationPageSheet) {
        // PageSheet模式
        return 0;
    } else {
        // FullScreen模式，返回状态栏底部坐标
        return TY_StatusBarHeight();
    }
}

@end
